function Report(repository) {
    this._repository = repository;
}

Report.prototype = {
    getReport: function(dateRange) {
        var months = this._repository.getApplicableMonths(dateRange);
        var report = months.select(function(month) {
            return new MonthReportView(month).render();
        });
        var json = JSON.stringify({ months: report });
        return json;
    }
};

function DayReportView(day, isMissingTravelDay) {
    this._day = day;    
    this._isMissingTravelDay = isMissingTravelDay;
}

DayReportView.prototype = {
    ActivityAbbreviationMap: { work: "(W)", sick: "(S)", vacation: '(V)', national: '(N)', other: "(O)" },
    ActivityFullnameMap: { work: i18n("LABEL_WORKDAYS"),
                        sick: i18n("LABEL_SICK_DAYS"),
                        vacation: i18n("LABEL_VACATION"),
                        national: i18n("LABEL_NATIONAL_HOLIDAY"),
                        other: i18n("LABEL_NON_WORKDAYS")
                    },
                        
    render: function() {
        var me = this;
        var result = {
            date: this._day.getDate().toString(CalendarConstants.JSONDateFormat),
            missingTravel: this._isMissingTravelDay,
            hasTravel: this._day.hasTravel(),
            hasTimeLost: this._day.isDuringTravel(),
            inCurrentMonth: true,
            note: this._day.hasNote() ? this._day.getNote()._content : ""
        };
        result.locations = this._day.getLocations().select(function(location) {
            return {
                country: location ? location.countryAbbreviation : "",
                taxUnit: location && !location.countryIsTaxUnit() ? location.taxUnitAbbreviation : "",
                fullname: location ? location.fullname : ""
            };
        });

        result.activities =
            this._day.getActivities().select(
                function(activity) {
                    return { abbreviation: me.ActivityAbbreviationMap[activity], fullname: me.ActivityFullnameMap[activity] };
                });

        return result;
    }
};



function MonthReportView(month) {
    this._month = month;
}

MonthReportView.prototype = {
    render: function() {
        var days = [];

        var month = this._month;
        month._daysInMonth.foreach(function(day) {
            var date = day.getDate();
            var isMissingTravelDay = month.isMissingTravelDay(date);
            var dayReportView = new DayReportView(day, isMissingTravelDay);
            days.push(dayReportView.render());
        });
        return { month: month.getYearMonth().month(), days: days, dateFormat: DefaultSetting.dateFormat() };
    }
};